<template>
  <div>
    <Button type="primary" @click="modalForm = true">添加数据</Button>
    <Button type="primary" @click="removes">删除多个</Button>

    <Table border :columns="columns" :data="data" @on-selection-change="onSelect"></Table>
    <Page :total="total" :page-size="rows" @on-change="onChangePage" :page-size-opts=[5,10,15,20] @on-page-size-change="onPageSizeChange" show-sizer />

    <Modal v-model="modalForm" title="数据操作">
      <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
        <FormItem label="商品名称" prop="goodsName">
          <Input v-model="formValidate.goodsName" placeholder="请输入商品名称"></Input>
        </FormItem> 
        <FormItem label="商品数量" prop="number">
          <Input v-model="formValidate.number" placeholder="购买的数量"></Input>
        </FormItem>

            <FormItem label="商品属性" prop="attr">
          <Input v-model="formValidate.attr" placeholder="请输商品的属性"></Input>
        </FormItem>
        <FormItem label="店铺ID" prop="shopID">
          <Input v-model="formValidate.shopId" placeholder="请输店铺ID"></Input>
        </FormItem>
        <FormItem label="收件人电话" prop="phone">
          <Input v-model="formValidate.phone" placeholder="请输入收件人电话"></Input>
        </FormItem>
        <FormItem label="商品单价" prop="price">
          <Input v-model="formValidate.price" placeholder="请输入商品单价"></Input>
        </FormItem>
        <!-- <FormItem label="商品金额" prop="email">
          <Input v-model="formValidate.email" placeholder="请输入email"></Input>
        </FormItem> -->
         <FormItem label="订单备注" prop="remark">
          <Input v-model="formValidate.remark" placeholder="请输备注"></Input>
        </FormItem>
        <FormItem label="收货地址" prop="site">
          <Input v-model="formValidate.site" placeholder="请输入收货地址"></Input>
        </FormItem> <FormItem label="订单状态" prop="start">
          <Input v-model="formValidate.start" placeholder="请输入订单状态"></Input>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="handleSubmit('formValidate')">Submit</Button>
          <Button @click="handleReset('formValidate')" style="margin-left: 8px">Reset</Button>
        </FormItem>
      </Form>
      <div slot="footer">
        我就不显示按钮
      </div>
    </Modal>
  </div>

</template>
<script>
import Base from '../../base/Base';
export default {
  mixins: [Base],
  data() {
    return {
      formValidate: {
        name    : '',
        password: ''
      },
      ruleValidate: {
        goodsName: [
          {
            required: true,
            message : '请输入商品输入姓名', 
            trigger : 'blur'
          }
        ],
        number: [
          {
            required: true,
            message : '必须输入一个数字',
            trigger : 'blur'
          }
        ],
           attr: [
          {
            required: true,
            message : '必须输入商品属性',
            trigger : 'blur'
          }
        ],
        shopId: [
          {
            required: true,
            message : '请输入店铺ID',
            trigger : 'blur'
          }
        ],
         phone: [
          {
            required: true,
            message : '必须输入收件人电话',
            trigger : 'blur'
          }
        ],
        price: [
          {
            required: true,
            message : '必须输入商品价格',
            trigger : 'blur'
          }
        ],
           remark: [
          {
            required: false,
          }
        ],
        site: [
          {
            required: true,
            message : '请输入收货地址',
            trigger : 'blur'
          }
        ],start: [
          {
            required: true,
            message : '请输入订单状态',
            trigger : 'blur'
          }
        ]
      },
      columns: [
        {
          type : 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: '商品名称',
          key  : 'goodsName',sortable: true
        },
        {
          title: '商品数量',
          key  : 'number',sortable: true
        },
        {
          title: '商品属性',
          key  : 'attr'
        },
        {
          title: '店铺ID',
          key  : 'shopId',sortable: true
        },{
          title: '收件人电话',
          key  : 'phone'
        },
        {
          title: '商品单价',
          key  : 'price',sortable: true
        },{
          title: '商品金额',
          key  : '',sortable: true
        },
        {
          title: '订单备注',
          key  : 'remark'
        },{
          title: '收货地址',
          key  : 'site'
        },{
          title: '订单状态',
          key  : 'start',sortable: true
        },
        {
          title : '操作',
          key   : 'action',
          width : 150,
          align : 'center',
          render: (h, params) => {
            return h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      this.edit(params.row._id);
                    }
                  }
                },
                '修改'
              ),
              h(
                'Button',
                {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  on: {
                    click: () => {
                      this.remove(params.row._id);
                    }
                  }
                },
                '删除'
              )
            ]);
          }
        }
      ]
    };
  }
};
</script>
